package net.st.controller.data;

import net.st.config.StConfig;
import net.st.meta.SearchDataMeta;
import net.st.model.SearchData;
import net.st.service.SearchDataService;
import net.st.util.DataUtil;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

public class ShowController extends Controller {

	private SearchDataService service = new SearchDataService();

	private SearchDataMeta meta = SearchDataMeta.get();

	@Override
	public Navigation run() throws Exception {
		String type = request.getParameter("type");
		SearchData searchData = service.get(asKey(meta.key));
		searchData.setNewFlag(StConfig.NEW_FLAG_OLD);
		service.update(searchData);
		if (DataUtil.isNotNull(type) && type.equals("diff")) {
			requestScope("htmlData", searchData.getDiffHtmlData());
		} else {
			requestScope("htmlData", searchData.getNewHtmlData());
		}
		return forward("/data/show.jsp");
	}
}